<template>
  <div class="dalog_one">
    <el-dialog
      title="创建用户"
      :visible="dialogVisible"
      width="45%"
      @close="btnClose"
    >
      <!-- <template #title /> -->
      <!-- <span>这是一段信息</span> -->
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
        <el-form-item label="企业名称" prop="shortName" label-width="20%">
          <el-input v-model="ruleForm.shortName" />
        </el-form-item>
        <el-form-item label="所属公司" prop="company" label-width="20%">
          <el-input v-model="ruleForm.company" />
        </el-form-item>
        <el-form-item label="活动区域" label-width="20%" style="margin-top:10px;">
          <!-- 隐藏区 -->
          <v-distpicker
            hide-area
            @province="onChangeProv"
            @city="onChangeCity"
          />
          <el-input
            v-model="ruleForm.province"
            type="hidden"
            style="display:none"
          />
          <el-input
            v-model="ruleForm.city"
            type="hidden"
            style="display:none"
          />
        </el-form-item>
        <el-form-item
          label="方向(企业标签)"
          prop="tags"
          label-width="20%"
          style="margin-top:10px;"
        >
          <el-input
            v-model="ruleForm.tags"
          />
        </el-form-item>
        <el-form-item
          label="备注"
          prop="remarks"
          label-width="20%"
        >
          <el-input
            v-model="ruleForm.remarks"
            type="textarea"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="btnClose">取 消</el-button>
        <el-button type="primary" @click="addCompany">确 定</el-button>
      </span>
    </el-dialog>
  </div>

</template>

<script>
import VDistpicker from 'v-distpicker'
import { addCompanys } from '@/api/company'
export default {
  components: { VDistpicker },
  props: {
    dialogVisible: {
      default: false,
      type: Boolean
    }
  },
  data() {
    return {
      cityOptions: [{
        value: '南京市',
        label: '南京市'
      }, {
        value: '合肥市',
        label: '合肥市'
      }, {
        value: '北京市',
        label: '北京市'
      }, {
        value: '上海市',
        label: '上海市'
      }, {
        value: '无锡市',
        label: '无锡市'
      }],
      value1: '',
      ruleForm: {
        remarks: '',
        tags: '',
        shortName: '',
        province: '',
        city: '',
        company: '',
        isFamous: true
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleChange(e) {
      console.log(e, '所选code值')
    },
    onChangeProv(e) {
      // console.log('省', e)
      this.ruleForm.province = e.value
    },
    // 监听市
    onChangeCity(e) {
      this.ruleForm.city = e.value
    },
    // 添加按钮
    addCompany() {
      this.$refs.ruleForm.validate(async() => {
        await addCompanys(this.ruleForm)
        this.$emit('changePage')
      })
      this.$emit('update:dialog-visible', false)
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    btnClose() {
      this.$emit('update:dialog-visible', false)
    }
  }
}
</script>
<style lang="scss">
#app .el-textarea__inner{
    height: 100px;
}
.dalog_one{

    .el-dialog{
    .el-dialog__header{
    background-color: skyblue;
}
}
}

</style>
